package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.Customer;
import com.ruoyi.business.service.ICustomerService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * customerController
 *
 * @author honor
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/business/customer")
@RequiredArgsConstructor
public class CustomerController extends BaseController
{
    private final ICustomerService customerService;

    /**
     * 查询customer列表
     */
    @ApiOperation("获取用户list")
    @PreAuthorize("@ss.hasPermi('business:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Customer customer)
    {
        startPage();
        List<Customer> list = customerService.selectCustomerList(customer);
        return getDataTable(list);
    }

    /**
     * 获取customer详细信息
     */
    @ApiOperation("获取customer详细信息")
    @PreAuthorize("@ss.hasPermi('business:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(customerService.selectCustomerById(id));
    }

    /**
     * 新增customer
     */
    @ApiOperation("新增customer")
    @PreAuthorize("@ss.hasPermi('business:customer:add')")
    @Log(title = "customer", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Customer customer)
    {
        return toAjax(customerService.insertCustomer(customer));
    }

    /**
     * 修改customer
     */
    @ApiOperation("修改customer")
    @PreAuthorize("@ss.hasPermi('business:customer:edit')")
    @Log(title = "customer", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Customer customer)
    {
        return toAjax(customerService.updateCustomer(customer));
    }

    /**
     * 删除customer
     */
    @ApiOperation("删除customer")
    @PreAuthorize("@ss.hasPermi('business:customer:remove')")
    @Log(title = "customer", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(customerService.deleteCustomerByIds(ids));
    }
}
